{extends '../layout.latte'}

{block content}
<a href="{route('blog')}">&lt; Back to blog</a>
<h1>{$post->title}</h1>
<p>Created by: {$post->username} on {$post->created_at|date:'d.m.Y G:i a'}.</p>
<div>
	{$post->content|breakLines}
</div>
<p n:if="$post->update_at">Last update: {$post->update_at|date:'d.m.Y G:i a'}.</p>

<h2>Comments</h2>
{foreach $post->comments as $comment}
<div>
	<p>{$comment->username} on {$comment->created_at|date:'d.m.Y G:i a'}.</p>
	<div>
		{$comment->content|breakLines}
	</div>
	<hr>
	{if permission('comment.destroy')}
	<a class="pseudo button" href="{route('comment_destroy', [ 'comment_id' => $comment->id ])}">Delete</a>
	{/if}
</div>
{else}
<p>No comments yet.</p>
{/foreach}

{if $username}
<h2>Add comment</h2>
<form action="{route('comment_store')}" method="post">
	<div>
		<label for="content">Comment:</label>
		<textarea name="content" id="content" placeholder="Comment" required></textarea>
	</div>
	<div>
		<button type="submit">Add Comment</button>
	</div>
</form>
{/if}
{/block}